package com.cictec.middleware.tde.rm.disp.receiver.handler;

import org.apache.mina.core.session.IoSession;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSON;
import com.cictec.middleware.feign.distribute.MiddlewareBusCanService;
import com.cictec.middleware.tde.rm.disp.annotation.HandleMessages;
import com.cictec.middleware.tde.rm.disp.receiver.AbstractReceiverHandler;
import com.cictec.middleware.tde.rm.protocol.TerminalMessage;
import com.cictec.middleware.tde.rm.protocol.rm.message.Rm0x0ATerminalMessage;

/**
 * 福田电动车指令解码
 * 
 * @author yy
 *
 */
@Component
@HandleMessages(0x0A)
public class TerminalElectricCarsHandler extends AbstractReceiverHandler {

	private static Logger logger = LoggerFactory.getLogger(TerminalElectricCarsHandler.class);

	@Autowired
	private MiddlewareBusCanService middlewareBusCanService;

	@Override
	public void handleMessage(TerminalMessage msg, IoSession session) {

		Rm0x0ATerminalMessage tcr = (Rm0x0ATerminalMessage) msg;

		middlewareBusCanService.uploadBusCan(tcr.getTerminalId(), JSON.toJSONString(tcr));

		logger.debug("【0x0A CAN总线数据】终端 {} Session {} data:{} ", msg.getTerminalId(), msg.getSessionId(), JSON.toJSONString(tcr));
	}

}
